// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   Axis.java

package com.java4less.rchart;

import com.java4less.rchart.gc.ChartColor;
import com.java4less.rchart.gc.ChartFont;
import com.java4less.rchart.gc.ChartGraphics;
import com.java4less.rchart.gc.GraphicsProvider;
import java.text.*;
import java.util.*;

// Referenced classes of package com.java4less.rchart:
//			ChartComponent, LineStyle, AxisTargetZone, ChartLabel, 
//			LogScale, Scale, Plotter, FillStyle, 
//			Chart

public class Axis extends ChartComponent
{

	public static final int HORIZONTAL = 0;
	public static final int VERTICAL = 1;
	public static final int CEROAXIS_LINE = 0;
	public static final int CEROAXIS_NO = 1;
	public static final int CEROAXIS_SCALE = 2;
	public static final int BAR_STYLE_NONE = 0;
	public static final int BAR_STYLE_BAR = 1;
	public static final int BAR_STYLE_RAISED_BAR = 2;
	public String label;
	public int barStyle;
	public int barWidth;
	public FillStyle barFilling;
	public boolean xscaleOnTop;
	public boolean axisFrame;
	public String dateLabelFormat;
	public String dateStep;
	public boolean dateStepPerUnit;
	public Date initialDate;
	protected int realPosition;
	protected int visibleSize;
	protected int offset;
	private int maxTickLabelLength;
	public boolean IntegerScale;
	public int autoNumberOfTicks;
	public double ticks_preferred_Interval[] = {
		0.10000000000000001D, 0.5D, 1.0D, 5D, 10D, 25D, 50D, 100D, 250D, 500D, 
		1000D, 5000D, 10000D, 50000D, 100000D, 500000D, 1000000D
	};
	public String scaleLabelFormat;
	public String labelTemplate;
	public boolean logarithmicIntervals;
	public Scale scale;
	public boolean bigTicksGrid;
	public double scaleTickInterval;
	public int bigTickInterval;
	public int bigTickIntervalList[];
	public int tickPixels;
	public int bigTickPixels;
	public Plotter plot;
	public Axis peerAxis;
	public int ceroAxis;
	public LineStyle ceroAxisStyle;
	public boolean tickAtBase;
	public int rotateLabels;
	public LineStyle style;
	public LineStyle gridStyle;
	public FillStyle gridFillStyle;
	public int orientation;
	protected boolean rightAxis;
	public ChartColor DescColor;
	public ChartFont DescFont;
	public String tickLabels[];
	public boolean startWithBigTick;
	public int tickLabelLength;
	protected Vector targetZones;
	protected boolean isMainAxis;
	protected Axis mainAxis;
	protected Vector additionalAxis;
	public boolean stackAdditionalAxis;

	public void addAdditionalAxis(Axis axis)
	{
		axis.isMainAxis = false;
		axis.mainAxis = this;
		additionalAxis.addElement(axis);
	}

	protected int getAdditionalAxisCount()
	{
		return additionalAxis.size();
	}

	protected Axis getAdditionalAxis(int i)
	{
		return (Axis)additionalAxis.elementAt(i);
	}

	public static double convertFromDate(Date d, String dateStep, Date initialDate)
	{
		long diff = d.getTime() - initialDate.getTime();
		double diff2 = diff;
		int step = 1;
		if (dateStep.length() > 1)
			step = (new Integer(dateStep.substring(1, dateStep.length()))).intValue();
		if (dateStep.toLowerCase().indexOf("d") == 0)
			diff2 = (double)diff / 86400000D;
		if (dateStep.toLowerCase().indexOf("m") == 0)
		{
			diff2 = (double)diff / 86400000D;
			diff2 /= 30D;
		}
		if (dateStep.toLowerCase().indexOf("w") == 0)
		{
			diff2 = (double)diff / 86400000D;
			diff2 /= 7D;
		}
		if (dateStep.toLowerCase().indexOf("y") == 0)
		{
			diff2 = (double)diff / 86400000D;
			diff2 /= 365D;
		}
		if (dateStep.toLowerCase().indexOf("h") == 0)
			diff2 = (double)diff / 3600000D;
		if (dateStep.toLowerCase().indexOf("s") == 0)
			diff2 = (double)diff / 1000D;
		if (dateStep.toLowerCase().indexOf("n") == 0)
			diff2 = (double)diff / 60000D;
		diff2 /= step;
		return diff2;
	}

	public Axis(int o, Scale s)
	{
		label = "";
		barStyle = 0;
		barWidth = 12;
		barFilling = null;
		xscaleOnTop = false;
		axisFrame = false;
		dateLabelFormat = "dd-MMM-yyyy";
		dateStep = "d";
		dateStepPerUnit = false;
		initialDate = null;
		visibleSize = 0;
		maxTickLabelLength = 0;
		IntegerScale = false;
		autoNumberOfTicks = 0;
		scaleLabelFormat = "";
		labelTemplate = "";
		logarithmicIntervals = false;
		bigTicksGrid = false;
		scaleTickInterval = 1.0D;
		bigTickInterval = 1;
		tickPixels = 4;
		bigTickPixels = 9;
		ceroAxis = 0;
		ceroAxisStyle = new LineStyle(0.2F, GraphicsProvider.getColor(ChartColor.DARKGRAY), 1);
		tickAtBase = false;
		rotateLabels = 0;
		style = new LineStyle(2.0F, GraphicsProvider.getColor(ChartColor.BLACK), 1);
		gridStyle = null;
		gridFillStyle = null;
		rightAxis = false;
		DescColor = GraphicsProvider.getColor(ChartColor.BLACK);
		DescFont = GraphicsProvider.getFont("Arial", ChartFont.PLAIN, 10);
		tickLabels = null;
		startWithBigTick = false;
		tickLabelLength = 1000;
		targetZones = new Vector();
		isMainAxis = true;
		mainAxis = null;
		additionalAxis = new Vector();
		stackAdditionalAxis = false;
		orientation = o;
		scale = s;
		if (o == 1)
			scale.reverse = true;
	}

	protected void drawForeground(ChartGraphics g, Axis peerAxis)
	{
		if (isMainAxis && !xscaleOnTop)
		{
			for (int i = 0; i < additionalAxis.size(); i++)
			{
				Axis a = (Axis)additionalAxis.elementAt(i);
				a.draw(g, peerAxis, true, false);
			}

		}
		draw(g, peerAxis, true, false);
	}

	protected void drawBackground(ChartGraphics g, Axis peerAxis)
	{
		maxTickLabelLength = 0;
		int tmpX = x;
		int tmpY = y;
		int realPositionY = realPosition;
		if (isMainAxis && !xscaleOnTop)
		{
			for (int i = 0; i < additionalAxis.size(); i++)
			{
				Axis a = (Axis)additionalAxis.elementAt(i);
				a.mainAxis = this;
				if (rightAxis)
					a.rightAxis = true;
				if (xscaleOnTop)
					a.xscaleOnTop = true;
				if (!stackAdditionalAxis)
				{
					if (orientation == 0 && !xscaleOnTop)
					{
						tmpY += height;
						realPositionY += height;
						a.realPosition = realPositionY;
					}
					if (orientation == 0 && xscaleOnTop)
					{
						tmpY -= height;
						realPositionY -= height;
						a.realPosition = realPositionY;
					}
					if (orientation == 1 && !rightAxis)
						tmpX -= width;
					if (orientation == 1 && rightAxis)
						tmpX += width;
					a.x = tmpX;
					a.y = tmpY;
					a.width = width;
					a.height = height;
					a.scale.screenMax = scale.screenMax;
					a.scale.screenMaxMargin = scale.screenMaxMargin;
					a.scale.screenMin = scale.screenMin;
				} else
				if (orientation == 1)
					a.x = x;
				else
					a.y = y;
				a.chart = chart;
				a.plot = plot;
				a.isMainAxis = false;
				a.visibleSize = visibleSize;
				a.draw(g, peerAxis, false, false);
			}

		}
		mainAxis = this;
		draw(g, peerAxis, false, false);
	}

	protected void drawGridBackground(ChartGraphics g, Axis peerAxis)
	{
		draw(g, peerAxis, false, true);
	}

	public void addTargetZone(AxisTargetZone zone)
	{
		if (zone != null)
			targetZones.addElement(zone);
	}

	public void removeTargetZones()
	{
		targetZones.removeAllElements();
	}

	public AxisTargetZone[] getTargetZones()
	{
		AxisTargetZone a[] = new AxisTargetZone[targetZones.size()];
		for (int i = 0; i < a.length; i++)
			a[i] = (AxisTargetZone)targetZones.elementAt(i);

		return a;
	}

	protected void paintTargetZones(ChartGraphics g, Axis peerAxis, int position)
	{
		for (int i = 0; i < targetZones.size(); i++)
		{
			AxisTargetZone z = (AxisTargetZone)targetZones.elementAt(i);
			z.chart = chart;
			z.paint(g, this, peerAxis, position);
		}

	}

	private String[] splitText(String s)
	{
		String r[] = new String[100];
		int lines = 0;
		if (tickLabelLength == 0)
			tickLabelLength = 1000;
		do
		{
			if (s.indexOf("\\n") <= -1 && s.length() <= tickLabelLength)
				break;
			if (s.indexOf("\\n") > -1 && s.indexOf("\\n") < tickLabelLength)
			{
				r[lines] = s.substring(0, s.indexOf("\\n"));
				s = s.substring(s.indexOf("\\n") + 2, s.length());
			} else
			{
				r[lines] = s.substring(0, tickLabelLength);
				s = s.substring(tickLabelLength, s.length());
			}
		} while (++lines < r.length);
		r[lines] = s;
		String a[] = new String[lines + 1];
		for (int i = 0; i <= lines; i++)
			a[i] = r[i];

		return a;
	}

	public void draw(ChartGraphics g, Axis peerAxis, boolean drawForeGround, boolean drawGridBackground)
	{
		double range = scale.max - scale.min;
		int numberBigTicks = 0;
		int numberTicks = 0;
		if (scale.min < 0.0D && scale.max < 0.0D)
			range = (scale.min - scale.max) * -1D;
		int bigTickCount = 0;
		int axisPosition = 0;
		int axisCeroPosition = 0;
		boolean drawTick = true;
		int effect3D = plot.depth;
		if (!isMainAxis && !mainAxis.stackAdditionalAxis)
			effect3D = 0;
		int lastGridPosition = 0;
		boolean fillGrid = false;
		double usedTickInterval = scaleTickInterval;
		if (autoNumberOfTicks > 0)
		{
			usedTickInterval = Math.abs(range / (double)autoNumberOfTicks);
			int proposedNumberOfTicks = 0;
			double bestTickInterval = usedTickInterval;
			if (ticks_preferred_Interval != null && ticks_preferred_Interval.length > 0)
			{
				for (int j = 0; j < ticks_preferred_Interval.length; j++)
				{
					if (proposedNumberOfTicks == 0)
						proposedNumberOfTicks = (int)Math.abs(range / ticks_preferred_Interval[j]);
					int newProposedNumberOfTicks = (int)Math.abs(range / ticks_preferred_Interval[j]);
					if (Math.abs(newProposedNumberOfTicks - autoNumberOfTicks) < Math.abs(proposedNumberOfTicks - autoNumberOfTicks))
					{
						proposedNumberOfTicks = newProposedNumberOfTicks;
						bestTickInterval = ticks_preferred_Interval[j];
						usedTickInterval = bestTickInterval;
					}
				}

			}
		}
		if (peerAxis.scale.min < 0.0D && peerAxis.scale.max > 0.0D)
			axisCeroPosition = peerAxis.scale.getScreenCoord(0.0D);
		if (orientation == 0)
		{
			if (ceroAxis == 2 && axisCeroPosition != 0)
				axisPosition = axisCeroPosition;
			else
				axisPosition = realPosition;
			if (drawForeGround)
			{
				if (!xscaleOnTop || axisFrame)
				{
					style.draw(g, x, axisPosition, x + visibleSize, axisPosition);
					if (!xscaleOnTop)
					{
						if (barFilling != null && barStyle != 0)
							barFilling.draw(g, x, axisPosition, x + visibleSize, axisPosition + barWidth);
						paintTargetZones(g, peerAxis, axisPosition);
						if (barStyle == 1)
							style.drawRect(g, x, axisPosition, x + visibleSize, axisPosition + barWidth);
						if (label.length() > 0)
						{
							ChartLabel clabel = new ChartLabel(label, "", false, false);
							g.setColor(DescColor);
							g.setFont(DescFont);
							clabel.initialize(g, chart);
							if (mainAxis.stackAdditionalAxis)
								clabel.paint(g, x, (y + height) - clabel.requiredHeight, 0, 0);
							else
								clabel.paint(g, x - clabel.requiredWidth - 4, axisPosition, 0, 0);
						}
					}
				}
				if ((axisFrame || xscaleOnTop) && peerAxis != null && effect3D == 0)
				{
					style.draw(g, x, axisPosition - peerAxis.visibleSize, x + visibleSize, axisPosition - peerAxis.visibleSize);
					if (xscaleOnTop)
					{
						if (barFilling != null && barStyle != 0)
							barFilling.draw(g, x, axisPosition - barWidth, x + visibleSize, axisPosition);
						paintTargetZones(g, peerAxis, axisPosition - barWidth);
						if (barStyle == 1)
							style.drawRect(g, x, axisPosition - barWidth, x + visibleSize, axisPosition);
						if (label.length() > 0)
						{
							ChartLabel clabel = new ChartLabel(label, "", false, false);
							g.setColor(DescColor);
							g.setFont(DescFont);
							clabel.initialize(g, chart);
							if (mainAxis.stackAdditionalAxis)
								clabel.paint(g, x, y, 0, 0);
							else
								clabel.paint(g, x - clabel.requiredWidth - 4, axisPosition - barWidth, 0, 0);
						}
					}
				}
			}
			if (!drawForeGround && !drawGridBackground)
			{
				int xs[] = new int[4];
				int ys[] = new int[4];
				int minPosition = peerAxis.scale.getScreenCoord(peerAxis.scale.min);
				int maxPosition = peerAxis.scale.getScreenCoord(peerAxis.scale.max);
				xs[0] = x + effect3D + offset;
				ys[0] = (axisPosition + peerAxis.offset) - effect3D;
				xs[1] = x + visibleSize + effect3D + offset;
				ys[1] = (axisPosition + peerAxis.offset) - effect3D;
				xs[2] = x + visibleSize + offset;
				ys[2] = axisPosition + peerAxis.offset;
				xs[3] = x + offset;
				ys[3] = axisPosition + peerAxis.offset;
				if (!rightAxis)
				{
					if (effect3D != 0)
						style.draw(g, xs[0], ys[0], xs[1], ys[1]);
					if (effect3D != 0)
						style.draw(g, xs[2], ys[2], xs[1], ys[1]);
					if (effect3D != 0)
						style.draw(g, xs[3], ys[3], xs[0], ys[0]);
					if (effect3D != 0)
						style.draw(g, xs[0], (plot.y - effect3D) + peerAxis.offset, xs[1], (plot.y - effect3D) + peerAxis.offset);
				}
			}
			if (axisCeroPosition != 0 && ceroAxis == 0 && !drawForeGround)
			{
				ceroAxisStyle.draw(g, x, axisCeroPosition, x + width, axisCeroPosition);
				if (!rightAxis)
				{
					if (effect3D != 0)
						ceroAxisStyle.draw(g, x + effect3D, axisCeroPosition - effect3D, x + width + effect3D, axisCeroPosition - effect3D);
					if (effect3D != 0)
						ceroAxisStyle.draw(g, x, axisCeroPosition, x + effect3D, axisCeroPosition - effect3D);
					if (effect3D != 0)
						ceroAxisStyle.draw(g, x + width, axisCeroPosition, x + width + effect3D, axisCeroPosition - effect3D);
				}
			}
		} else
		{
			if (ceroAxis == 2 && axisCeroPosition != 0)
				axisPosition = axisCeroPosition;
			else
			if (!isMainAxis && rightAxis)
				axisPosition = x;
			else
			if (rightAxis)
				axisPosition = realPosition;
			else
				axisPosition = x + width;
			if (drawForeGround)
			{
				style.draw(g, axisPosition, y, axisPosition, y + visibleSize);
				if (axisFrame && peerAxis != null && effect3D == 0 && !rightAxis)
					style.draw(g, axisPosition + peerAxis.visibleSize, y, axisPosition + peerAxis.visibleSize, y + visibleSize);
				if (!rightAxis)
				{
					if (barFilling != null && barStyle != 0)
						barFilling.draw(g, axisPosition - barWidth, y, axisPosition, y + visibleSize);
					paintTargetZones(g, peerAxis, axisPosition - barWidth);
					if (barStyle == 1)
						style.drawRect(g, axisPosition - barWidth, y, axisPosition, y + visibleSize);
					if (label.length() > 0)
					{
						ChartLabel clabel = new ChartLabel((new StringBuilder()).append("@rotation value='90' center='LEFTTOP'@").append(label).toString(), "", false, false);
						g.setColor(DescColor);
						g.setFont(DescFont);
						clabel.initialize(g, chart);
						if (mainAxis.stackAdditionalAxis)
							clabel.paint(g, x, y, 0, 0);
						else
							clabel.paint(g, axisPosition - barWidth, y + visibleSize + 4, 0, 0);
					}
				}
				if (rightAxis)
				{
					if (barFilling != null && barStyle != 0)
						barFilling.draw(g, axisPosition, y, axisPosition + barWidth, y + visibleSize);
					paintTargetZones(g, peerAxis, axisPosition);
					if (barStyle == 1)
						style.drawRect(g, axisPosition, y, axisPosition + barWidth, y + visibleSize);
					if (label.length() > 0)
					{
						ChartLabel clabel = new ChartLabel((new StringBuilder()).append("@rotation value='90'  center='LEFTTOP'@").append(label).toString(), "", false, false);
						g.setColor(DescColor);
						g.setFont(DescFont);
						clabel.initialize(g, chart);
						if (mainAxis.stackAdditionalAxis)
							clabel.paint(g, (axisPosition + width) - clabel.requiredHeight, y, 0, 0);
						else
							clabel.paint(g, axisPosition, y + visibleSize + 4, 0, 0);
					}
				}
			}
			if (!drawForeGround && !drawGridBackground)
			{
				int xs[] = new int[4];
				int ys[] = new int[4];
				int xs2[] = new int[4];
				int ys2[] = new int[4];
				int minPosition = peerAxis.scale.getScreenCoord(peerAxis.scale.min);
				int maxPosition = peerAxis.scale.getScreenCoord(peerAxis.scale.max);
				xs[0] = axisPosition + peerAxis.offset + effect3D;
				ys[0] = (y - effect3D) + offset;
				xs[1] = axisPosition + peerAxis.offset + effect3D;
				ys[1] = ((y + visibleSize) - effect3D) + offset;
				xs[2] = axisPosition + peerAxis.offset;
				ys[2] = y + visibleSize + offset;
				xs[3] = axisPosition + peerAxis.offset;
				ys[3] = y + offset;
				xs2[0] = axisPosition + peerAxis.visibleSize + effect3D + peerAxis.offset;
				ys2[0] = ys[0];
				xs2[1] = axisPosition + peerAxis.visibleSize + effect3D + peerAxis.offset;
				ys2[1] = ys[1];
				xs2[2] = xs[1];
				ys2[2] = ys[1];
				xs2[3] = xs[0];
				ys2[3] = ys[0];
				if (!rightAxis)
				{
					if (effect3D != 0)
						style.draw(g, xs[0], ys[0], xs[1], ys[1]);
					if (effect3D != 0)
						style.draw(g, xs[2], ys[2], xs[1], ys[1]);
					if (effect3D != 0)
						style.draw(g, xs[3], ys[3], xs[0], ys[0]);
					if (effect3D != 0)
						style.draw(g, xs2[0], ys2[0], xs2[1], ys2[1]);
				}
			}
			if (axisCeroPosition != 0 && ceroAxis == 0 && !drawForeGround)
			{
				ceroAxisStyle.draw(g, axisCeroPosition, y, axisCeroPosition, y + height);
				if (!rightAxis)
				{
					if (effect3D != 0)
						ceroAxisStyle.draw(g, axisCeroPosition + effect3D, y - effect3D, axisCeroPosition + effect3D, (y + height) - effect3D);
					if (effect3D != 0)
						ceroAxisStyle.draw(g, axisCeroPosition, y + height, axisCeroPosition + effect3D, (y + height) - effect3D);
					if (effect3D != 0)
						ceroAxisStyle.draw(g, axisCeroPosition, y, axisCeroPosition + effect3D, y - effect3D);
				}
			}
		}
		double tickBase = scale.min;
		int iteration = 0;
		int hh;
		if (logarithmicIntervals)
			hh = 0;
		if (startWithBigTick)
			bigTickCount = bigTickInterval - 1;
		Date tickDate = null;
		if (initialDate != null)
			tickDate = initialDate;
		double i2 = tickBase;
		double startValue = tickBase;
		if (startValue == 0.0D)
			startValue = 1.0D;
		double i = tickBase;
		do
		{
			if (i > scale.max || iteration > 1000)
				break;
			iteration++;
			boolean nowBigTick = false;
			if (iteration > 1 || tickAtBase)
			{
				numberTicks++;
				bigTickCount++;
				int v = scale.getScreenCoord(i);
				if (bigTickIntervalList == null && bigTickCount == bigTickInterval)
					nowBigTick = true;
				if (bigTickIntervalList != null)
				{
					for (int j = 0; j < bigTickIntervalList.length; j++)
						if (numberTicks == bigTickIntervalList[j])
							nowBigTick = true;

				}
				int tickLength;
				if (nowBigTick)
				{
					bigTickCount = 0;
					tickLength = bigTickPixels;
				} else
				{
					tickLength = tickPixels;
				}
				drawTick = true;
				if (drawTick)
				{
					if (i != scale.min && !drawForeGround && drawGridBackground && gridFillStyle != null && (bigTickCount == 0 || !bigTicksGrid))
					{
						if (orientation == 0)
						{
							if (fillGrid)
								gridFillStyle.draw(g, lastGridPosition + 1, plot.y - effect3D, v + effect3D, (plot.y + plot.height) - effect3D);
							lastGridPosition = v + effect3D;
						} else
						{
							if (fillGrid)
								gridFillStyle.draw(g, plot.x + effect3D, (v - effect3D) + 1, plot.x + plot.width + effect3D, lastGridPosition);
							lastGridPosition = v - effect3D;
						}
						fillGrid = !fillGrid;
					}
					if (i != scale.min && !drawForeGround && !drawGridBackground && gridStyle != null && (bigTickCount == 0 || !bigTicksGrid) && (ceroAxis != 0 || i != 0.0D))
						if (orientation == 0)
						{
							if (effect3D != 0)
								gridStyle.draw(g, v, plot.y + plot.height, v + effect3D, (plot.y + plot.height) - effect3D);
							gridStyle.draw(g, v + effect3D, plot.y - effect3D, v + effect3D, (plot.y + plot.height) - effect3D);
						} else
						{
							gridStyle.draw(g, plot.x + effect3D, v - effect3D, plot.x + plot.width + effect3D, v - effect3D);
							if (effect3D != 0)
								gridStyle.draw(g, plot.x, v, plot.x + effect3D, v - effect3D);
						}
				}
				if (drawForeGround)
				{
					if (drawTick)
						if (orientation == 0)
						{
							if (v - offset >= x && v - offset <= visibleSize + x)
								if (!xscaleOnTop)
									style.draw(g, v - offset, axisPosition, v - offset, axisPosition + tickLength);
								else
									style.draw(g, v - offset, axisPosition - peerAxis.visibleSize, v - offset, axisPosition - peerAxis.visibleSize - tickLength);
						} else
						if (rightAxis)
						{
							if (v - offset >= y && v - offset <= visibleSize + y)
								style.draw(g, axisPosition, v - offset, axisPosition + tickLength, v - offset);
						} else
						if (v - offset >= y && v - offset <= visibleSize + y)
							style.draw(g, axisPosition - tickLength, v - offset, axisPosition, v - offset);
					if (bigTickCount == 0)
					{
						numberBigTicks++;
						g.setColor(DescColor);
						g.setFont(DescFont);
						String txt = (new Double(i)).toString();
						if (scaleLabelFormat.length() > 0)
						{
							DecimalFormat df = null;
							if (Chart.numberLocale == null)
							{
								df = new DecimalFormat(scaleLabelFormat);
							} else
							{
								NumberFormat nf = NumberFormat.getNumberInstance(new Locale(Chart.numberLocale, ""));
								df = (DecimalFormat)nf;
								df.applyPattern(scaleLabelFormat);
							}
							txt = df.format(new Double(i));
						}
						if (IntegerScale)
							txt = (new Integer((int)i)).toString();
						if (tickDate != null)
							txt = (new SimpleDateFormat(dateLabelFormat)).format(tickDate);
						ChartLabel formattedlabel = null;
						if (tickLabels != null)
							if (tickLabels.length >= numberBigTicks)
							{
								if (tickLabels[numberBigTicks - 1] != null)
								{
									formattedlabel = new ChartLabel(tickLabels[numberBigTicks - 1], txt, false, true);
									txt = tickLabels[numberBigTicks - 1];
								} else
								{
									txt = " ";
								}
							} else
							{
								txt = " ";
							}
						if (formattedlabel == null && labelTemplate.length() > 0)
							formattedlabel = new ChartLabel(labelTemplate, txt, false, false);
						boolean labelPainted = false;
						if (rotateLabels != 0 && orientation == 0 && v - offset >= x && v - offset <= visibleSize + x)
						{
							int textWidth = g.getFontWidth(DescFont, txt);
							if (!xscaleOnTop)
								labelPainted = g.drawRotatedText(DescFont, DescColor, txt, rotateLabels, v - offset, realPosition + tickLength, false);
							else
								labelPainted = g.drawRotatedText(DescFont, DescColor, txt, rotateLabels, v - offset, realPosition - bigTickPixels - peerAxis.visibleSize - textWidth - 2, false);
							if (maxTickLabelLength < textWidth)
								maxTickLabelLength = textWidth;
						}
						if (rotateLabels != 0 && orientation == 1 && v - offset >= y && v - offset <= visibleSize + y)
						{
							int lblx = 0;
							int lbly = 0;
							int textHeight = g.getFontHeight(DescFont);
							if (rightAxis)
							{
								lblx = realPosition + tickLength + 1;
							} else
							{
								lblx = (x + width) - tickLength - g.getFontHeight(null);
								if (barStyle != 0)
									lblx = (x + width) - barWidth - g.getFontHeight(null);
							}
							lbly = v - g.getFontWidth(null, txt) / 2;
							labelPainted = g.drawRotatedText(DescFont, DescColor, txt, rotateLabels, lblx, lbly - offset, false);
							if (maxTickLabelLength < textHeight)
								maxTickLabelLength = textHeight;
						}
						if (!labelPainted && drawTick && formattedlabel != null)
						{
							formattedlabel.initialize(g, super.chart);
							labelPainted = true;
							int lblw = formattedlabel.requiredWidth;
							int lblh = formattedlabel.requiredHeight;
							int lblx = 0;
							int lbly = 0;
							if (orientation == 1)
							{
								if (rightAxis && !isMainAxis)
								{
									lblx = x + tickLength + 3;
									if (barStyle != 0)
										lblx = x + barWidth + 3;
								} else
								if (rightAxis)
								{
									lblx = realPosition + tickLength + 3;
									if (barStyle != 0)
										lblx = realPosition + barWidth + 3;
								} else
								{
									lblx = (x + width) - tickLength - lblw;
									if (barStyle != 0)
										lblx = (x + width) - barWidth - lblw;
								}
								lbly = v - formattedlabel.requiredHeight;
								if (lbly - offset >= y && lbly - offset <= visibleSize + y)
									formattedlabel.paint(g, lblx, lbly - offset, formattedlabel.requiredWidth, formattedlabel.requiredHeight);
								if (maxTickLabelLength < formattedlabel.getRotatedWidth())
									maxTickLabelLength = formattedlabel.getRotatedWidth();
							} else
							{
								lblx = v - lblw / 2;
								lbly = realPosition + tickLength;
								if (xscaleOnTop && !isMainAxis)
									lbly = y - peerAxis.visibleSize - formattedlabel.requiredHeight - barWidth - tickLength;
								if (xscaleOnTop && isMainAxis)
									lbly = lbly - peerAxis.visibleSize - formattedlabel.requiredHeight - barWidth - tickLength;
								if (v - offset >= x && v - offset <= visibleSize + x)
									formattedlabel.paint(g, lblx - offset, lbly, formattedlabel.requiredWidth, formattedlabel.requiredHeight);
								if (maxTickLabelLength < formattedlabel.getRotatedHeight())
									maxTickLabelLength = formattedlabel.getRotatedHeight();
							}
						}
						if (!labelPainted && drawTick)
						{
							String txts[] = splitText(txt);
							int lblw = g.getFontWidth(null, (new StringBuilder()).append(txts[0]).append(" ").toString());
							int lblh = g.getFontHeight(null);
							int lblx = 0;
							int lbly = 0;
							if (orientation == 1)
							{
								if (rightAxis && !isMainAxis)
								{
									lblx = x + tickLength + 3;
									if (barStyle != 0)
										lblx = x + barWidth + 3;
								} else
								if (rightAxis)
								{
									lblx = realPosition + tickLength + 3;
									if (barStyle != 0)
										lblx = realPosition + barWidth + 3;
								} else
								{
									lblx = (x + width) - tickLength - lblw;
									if (barStyle != 0)
										lblx = (x + width) - barWidth - lblw;
								}
								lbly = v;
								if (lbly - offset >= y && lbly - offset <= visibleSize + y)
									g.drawString(txts[0], lblx, lbly - offset);
								for (int h = 1; h < txts.length; h++)
								{
									int lblw1 = g.getFontWidth(null, txts[h]);
									if (rightAxis)
										lblx = realPosition + tickLength + 1;
									else
										lblx = (x + width) - tickLength - lblw1;
									if (lbly - offset >= y && lbly - offset <= visibleSize + y)
										g.drawString(txts[h], lblx, (lbly - offset) + lblh * h);
								}

							} else
							{
								lblx = v - lblw / 2;
								lbly = realPosition + tickLength + lblh;
								if (xscaleOnTop && isMainAxis)
									lbly = lbly - peerAxis.visibleSize - txts.length * lblh - lblh - barWidth;
								if (xscaleOnTop && !isMainAxis)
									lbly = y - peerAxis.visibleSize - txts.length * lblh - lblh - barWidth;
								if (v - offset >= x && v - offset <= visibleSize + x)
									g.drawString(txts[0], lblx - offset, lbly);
								for (int h = 1; h < txts.length; h++)
								{
									int lblw1 = g.getFontWidth(null, txts[h]);
									lblx = v - lblw1 / 2;
									if (v - offset >= x && v - offset <= visibleSize + x)
										g.drawString(txts[h], lblx - offset, lbly + lblh * h);
								}

							}
						}
					}
				}
			}
			if (logarithmicIntervals && (scale instanceof LogScale))
			{
				if (bigTickInterval == 1 || bigTickCount == bigTickInterval - 1)
				{
					i = i2;
					if (scaleTickInterval == 0.0D)
					{
						if (i == 0.0D)
							i = 1.0D;
						i *= ((LogScale)scale).base;
					} else
					{
						i += scaleTickInterval;
					}
					i2 = i;
				} else
				{
					double smallTickInterval = 0.0D;
					double i3 = i2;
					if (scaleTickInterval == 0.0D)
					{
						if (i3 == 0.0D)
							i3 = 1.0D;
						i3 *= ((LogScale)scale).base;
					} else
					{
						i3 += scaleTickInterval;
					}
					smallTickInterval = i3 - i2;
					smallTickInterval /= bigTickInterval;
					i += smallTickInterval;
				}
			} else
			{
				i += usedTickInterval;
				i = Math.rint(i * 100000D) / 100000D;
				if (tickDate != null)
				{
					int step = 1;
					if (dateStep.length() > 1)
						step = (new Integer(dateStep.substring(1, dateStep.length()))).intValue();
					if (dateStepPerUnit)
						step = (int)((double)step * usedTickInterval);
					Calendar c = Calendar.getInstance();
					c.setTime(tickDate);
					if (dateStep.toLowerCase().indexOf("d") == 0)
						c.add(5, step);
					if (dateStep.toLowerCase().indexOf("m") == 0)
						c.add(2, step);
					if (dateStep.toLowerCase().indexOf("w") == 0)
						c.add(5, step * 7);
					if (dateStep.toLowerCase().indexOf("y") == 0)
						c.add(1, step);
					if (dateStep.toLowerCase().indexOf("h") == 0)
						c.add(10, step);
					if (dateStep.toLowerCase().indexOf("s") == 0)
						c.add(13, step);
					if (dateStep.toLowerCase().indexOf("n") == 0)
						c.add(12, step);
					tickDate = c.getTime();
				}
			}
		} while (true);
	}
}
